package com.example.studyroom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.studyroom.Entity.Reservation;

import com.example.studyroom.dto.StudyRoomAdmin.HandleReservationDTO;
import com.example.studyroom.dto.User.UserReserveDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReservationMapper extends BaseMapper<Reservation> {
    //插入预约信息
    @Insert("INSERT INTO Reservation (Uname, roomName, startTime, endTime, reserveStatus) VALUES (#{uname}, #{roomName}, #{startTime}, #{endTime}, #{reserveStatus})")
    void UserReserve(Reservation reservation);

    //显示该用户的所有预约信息
    @Select("SELECT * from Reservation WHERE Uname= #{Uname}")
    List<UserReserveDTO> getReservationByUser(@Param("Uname") String Uname);

    //用户取消预约
    @Update("UPDATE Reservation SET reserveStatus = '已取消' WHERE id = #{id}")
    void cancelReservation(@Param("id") Integer id);

    //显示该管理员所负责的自习室的所有预约
    @Select("SELECT * FROM Reservation WHERE roomName IN " +
            "(SELECT roomName FROM StudyRoom WHERE adminName = #{adminName})")
    List<HandleReservationDTO> getReservationByAdmin(@Param("adminName") String adminName);

    //管理员审核预约
    @Update("UPDATE Reservation SET reserveStatus = '审核通过' WHERE id = #{id}")
    void handleReservation(Integer id);
}
